package com.codefish.framework.spring.core.io;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * @author <a href='https://gitee.com/hzf2281'>codefish</a>
 * @version 1.0.0
 * @since 2022/09/30 下午 03:15
 */
public class UrlResource implements Resource {
    private final String urlPath;
    private final URL url;

    public UrlResource(String urlPath) throws MalformedURLException {
        this.urlPath = urlPath;
        this.url = new URL(urlPath);
    }

    @Override
    public InputStream getInputStream() throws IOException {
        return this.url.openStream();
    }

    @Override
    public String getResourceName() {
        return this.url.getPath();
    }

    @Override
    public String getResourcePath() {
        return this.urlPath;
    }
}
